"""
@author: mark
@contact: QQ:1241642375
@Created on: 2024年8月17日18:17:46
@Remark: 视图层
"""
from django.shortcuts import render

# Create your views here.
from sales.models import SaleField, SaleData
from sales.serializers import  SaleFieldSerializer, SaleFieldCreateUpdateSerializer, SaleFieldResourceSerializer, SaleDataSerializer, SaleDataCreateUpdateSerializer, SaleDataResourceSerializer
from dvadmin.utils.viewset import CustomModelViewSet


class SaleFieldViewSet(CustomModelViewSet):
    """
    list:查询
    create:新增
    update:修改
    retrieve:单例
    destroy:删除
    """
    queryset = SaleField.objects.all()
    serializer_class = SaleFieldSerializer
    create_serializer_class = SaleFieldCreateUpdateSerializer
    update_serializer_class = SaleFieldCreateUpdateSerializer

    # 配置导出
    export_field_label = {
        "field_category": "分类",
        "field_name": "字段名称",
        "field_key": "字段key",
        "calculation_type":"计算类型",
        "calculation_formula":"计算方案",
        "selection_list":"选择key",
        "edit_en":"编辑使能",
        "creator": "创建人",
        "modifier": "修改人",
    }

    export_serializer_class = SaleFieldResourceSerializer


class SaleDataViewSet(CustomModelViewSet):
    """
    list:查询
    create:新增
    update:修改
    retrieve:单例
    destroy:删除
    """
    queryset = SaleData.objects.all()
    serializer_class = SaleDataSerializer
    create_serializer_class = SaleDataCreateUpdateSerializer
    update_serializer_class = SaleDataCreateUpdateSerializer

    # 配置导出
    export_field_label = {
        "department": "部门",
        "sale_time": "销售日期",
        "sale_data": "销售数据",
        "creator":"创建人",
        "modifier": "修改人",
    }
    export_foreignKey__value_column = ('department', 'creator', 'modifier')

    export_serializer_class = SaleDataResourceSerializer